<template>
	<view class="wrap">

    <u-tabs :list="list1" @click="click"></u-tabs>
    <u-gap height="200"></u-gap>
    <!-- <u-tag text="标签"></u-tag> -->
    <u-skeleton	rows="3" :loading="skeletonLoading" title	titleWidth="20%" rowsHeight="25" :rowsWidth="['20%', '80%', '80%']">
      <view>
        <view class="u-demo-block__content"><u-tag text="标签"></u-tag></view>
        <view class="u-demo-block__content"><u-tag :text="'抒情'"/></view>
      </view>
    </u-skeleton>
    <button open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">唤起授权</button>
    <u-gap height="50"></u-gap>

    <u--text type="info" align="center" text="使用该微信授权future登录"></u--text>
    <u-gap height="50"></u-gap>
		<u-button type="primary" text="确认" @click="testLimit()"></u-button>
    <u-gap height="10"></u-gap>
    <u-button text="取消"></u-button>
	</view>
</template>

<script>
  import { scan } from '@/api/authing'
  import { searh } from '@/api/poetry'

  // 条件判断
  const { platform } = uni.$u

	export default {
		data() {
			return {
        skeletonLoading: false,
         list1: [{ name: '发票抬头',}, { name: '通信地址', }, { name: '获取用户信息'}, { name: '科技' }]
			}
		},
		onLoad(options) {
      // 打开调试
      // uni.setEnableDebug({ enableDebug: true })
      const extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {}
      console.log(extConfig)
      let that = this
      console.log('1111,platform: ',platform,this.$store.getters.phone)
      if(platform === 'mp') {
      const accountInfo = uni.getAccountInfoSync();
      console.log(accountInfo.miniProgram.appId); // 小程序 appId



      }
		},
		methods: {
      click(item) {
        console.log('item', item)
        switch(item.index){
          case 0:
            uni.authorize({scope: 'scope.invoiceTitle',success() {uni.chooseInvoiceTitle()}})
            break
          case 1:
            uni.authorize({scope: 'scope.address',success() { uni.chooseAddress() }})
            break
          case 2:
            this.getUserInfo()
            break
          default:
            console.log('00000000000000')
            break
        }
      },
      testLimit(){
        searh({params: {key:'李白'},custom: { auth: true,toast: false }}).then(response => {
          console.log(response.msg)
        })
      },
      getUserInfo(){
        // 获取用户信息
        uni.getUserInfo({
          provider: 'weixin',
          success: function (infoRes) {
            console.log('用户昵称为：' + JSON.stringify(infoRes.userInfo));
            uni.$u.toast(JSON.stringify(infoRes.userInfo))
            const sceneStr = decodeURIComponent(options.scene);//这里的值就是二维码里带的参数值
            scan({uniCode: '123456',appid: 'wx02842ea48ec5114f',phone: that.$store.getters.phone}
            ,{custom: { auth: false,toast: false }}).then(() => {

            }).catch(() =>{

            })
          }
        })
      },
      onGetPhoneNumber(e){
        if(e.detail.errMsg == "getPhoneNumber:ok"){
            console.log("用户点击了接受")
            console.log(e.detail);
            let encryptedData = e.detail.encryptedData
            let errMsg = e.detail.errMsg
            let iv = e.detail.iv
        }else{
            console.log("用户点击了拒绝")
        }
      }
		}
	}
</script>

<style lang="scss">
.u-demo-block {
	flex: 1;
	margin-bottom: 23px;

	&__content {
		@include flex(column);
	}

	&__title {
		font-size: 14px;
		color: rgb(143, 156, 162);
		margin-bottom: 8px;
		@include flex;
	}
}
  .u-demo-block__content{
    flex-direction: row;
		flex-wrap: wrap;
		align-items: center;
  }

</style>
